package controller;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

@SuppressWarnings("serial")
public class CheckTypeLinkServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		
		response.setContentType("text/plain");
		String url = request.getParameter("url");
		
		url = Utils.fomatSitemap(url);
		
		String charset = "UTF-8";
		String type="";
		
		ArrayList<String> site = Utils.getStachSite();
		
		
		try {
			Document doc = null;
			
			if(site.contains(Utils.fomatDmain(url)))
			{
				type = "3";
			} else {
				doc = Jsoup.parse(Utils.GetHtml(url, charset));
			}
			if(!"3".equals(type))
			{
				if("".equals(doc.select("rss").html()))
				{
					if("".equals(doc.select("feed").html()))
					{
						type="1";
					} else {
						type="2";
					}
				} else {
					type="2";
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		response.getWriter().println(type);
	}
}
